Post

Replies

Boosts

Views

Activity

SwiftData crashes with @Query using major/minor sort descriptors
Using Xcode Version 15.0 beta (15A5160n) steps to reproduce: Insert the code below into a new project Build and run First time, tap the “Setup” button to populate the SwiftData container. All of the Attribute objects will be shown together sorted by ‘Attribute.order’ Comment out the @Query with the single SortDescriptor and then uncomment the @Query with two SortDescriptor's. Run the project again and it will crash with the following console message: SwiftData/DataUtilities.swift:1179: Fatal error: Unexpected type for Expansion: Item The expectation was for the Attributes to be listed in order within groups for each Item object, also in order by their Item.order property: Item[0] Attribute[0] Item[0] Attribute[1] Item[0] Attribute[2] Item[1] Attribute[0] Item[1] Attribute[1] Item[1] Attribute[2] Item[2] Attribute[0] Item[2] Attribute[1] Item[2] Attribute[2] I have filed a Feedback for this crash, which occurs when running this project on both the macOS Sonoma beta and the iOS 17.0 iPhone 14 Pro simulator. Should this work? Is there a workaround? Is there an alternate method to accomplish the same results? **** BTW, this same sorting pattern has worked well with Core Data in the past. import SwiftUI import SwiftData @Model final class Item { var name: String var order: Int @Relationship(.cascade) var attributes: [Attribute] = [] init(name: String, order: Int) { self.name = name self.order = order } } @Model final class Attribute { var name: String var order: Int @Relationship var item: Item init(item: Item, name: String, order: Int) { self.item = item self.name = name self.order = order } } struct ContentView: View { @Environment(\.modelContext) private var modelContext @Query(FetchDescriptor<Attribute>(sortBy: [SortDescriptor(\Attribute.order, order: .forward)])) // @Query(FetchDescriptor<Attribute>(sortBy: [SortDescriptor(\Attribute.item.order, order: .forward), // SortDescriptor(\Attribute.order, order: .forward)])) private var attributes: [Attribute] var body: some View { NavigationView { List { ForEach(self.attributes) { attribute in Text("Item[\(attribute.item.order)] Attribute[\(attribute.order)]") .monospaced() } } .toolbar { ToolbarItem { Button("Setup", action: self.setup) } } } } private func setup() { withAnimation { do { let attributeDescriptor = FetchDescriptor<Attribute>() let attributes = try self.modelContext.fetch(attributeDescriptor) for attribute in attributes { self.modelContext.delete(attribute) } let itemDescriptor = FetchDescriptor<Item>() let items = try self.modelContext.fetch(itemDescriptor) for item in items { self.modelContext.delete(item) } try self.modelContext.save() let item1 = Item(name: "Z", order: 0) self.modelContext.insert(Attribute(item: item1, name: "\(item1.name).0", order: 0)) self.modelContext.insert(Attribute(item: item1, name: "\(item1.name).1", order: 1)) self.modelContext.insert(Attribute(item: item1, name: "\(item1.name).2", order: 2)) self.modelContext.insert(item1) let item2 = Item(name: "Y", order: 1) self.modelContext.insert(Attribute(item: item2, name: "\(item2.name).0", order: 0)) self.modelContext.insert(Attribute(item: item2, name: "\(item2.name).1", order: 1)) self.modelContext.insert(Attribute(item: item2, name: "\(item2.name).2", order: 2)) self.modelContext.insert(item2) let item3 = Item(name: "X", order: 2) self.modelContext.insert(Attribute(item: item3, name: "\(item3.name).0", order: 0)) self.modelContext.insert(Attribute(item: item3, name: "\(item3.name).1", order: 1)) self.modelContext.insert(Attribute(item: item3, name: "\(item3.name).2", order: 2)) self.modelContext.insert(item2) try self.modelContext.save() } catch { let nsError = error as NSError fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } } } }
3
0
1.8k
Jun ’23
Using Passkeys on Apple sites
I have two AppleID's. I use one with my Apple Developer account and the other is my primary AppleID that I mainly use for everything else. In the past, I have used them on separate MacBooks, but I am now trying to consolidate everything onto one MacBook. I have created a Passkey for my Apple.com store account and that works well. However, when I try to log into an Apple developer related site (e.g. developer.apple.com), it initially offers to use my personal Passkey with an option to use a different AppleID. When I select "use a different AppleID" and select my developer AppleID, it only allows me to log in with a password or with a QR code using a Passkey on a different device. Is it possible to set up a Passkey for my Apple developer account on the same MacBook that already has a passkey set up for my Apple store account? If so, what is the process to create it. If it helps, both of my AppleID's are members of the same Family. Thanks.
2
0
662
Jun ’24